package com.ruoyi.web.controller.productionre;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.production.domain.FertilizerReturn;
import com.ruoyi.production.domain.SimpleProduction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.GraftingclipReturn;
import com.ruoyi.production.service.IGraftingclipReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 嫁接夹退回Controller
 *
 * @author ruoyi
 * @date 2021-07-20
 */
@Api("嫁接夹退回")
@RestController
@RequestMapping("/production/graftingclipre")
public class GraftingclipReturnController extends BaseController
{
    @Autowired
    private IGraftingclipReturnService graftingclipReturnService;

    /**
     * 查询嫁接夹退回列表
     */
    @ApiOperation("查询嫁接夹退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:list')")
    @GetMapping("/list")
    public TableDataInfo list(GraftingclipReturn graftingclipReturn)
    {
        startPage();
        List<GraftingclipReturn> list = graftingclipReturnService.selectGraftingclipReturnList(graftingclipReturn);
        return getDataTable(list);
    }

    /**
     * 导出嫁接夹退回列表
     */
    @ApiOperation("导出嫁接夹退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:export')")
    @Log(title = "嫁接夹退回", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GraftingclipReturn graftingclipReturn)
    {
        List<GraftingclipReturn> list=new ArrayList();
        //通过id来取
        Long a[]=graftingclipReturn.getGraftingclipReturnIds();
        for(int i=0;i<a.length;i++) {
            GraftingclipReturn list1 = graftingclipReturnService.selectGraftingclipReturnById(a[i]);
            list.add(list1);
        }

        ExcelUtil<GraftingclipReturn> util = new ExcelUtil<GraftingclipReturn>(GraftingclipReturn.class);
        return util.exportExcel(list, "嫁接夹退回数据");
    }

    /**
     * 获取嫁接夹退回详细信息
     */
    @ApiOperation("获取嫁接夹退回详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:query')")
    @GetMapping(value = "/{graftingclipReturnId}")
    public AjaxResult getInfo(@PathVariable("graftingclipReturnId") Long graftingclipReturnId)
    {
        return AjaxResult.success(graftingclipReturnService.selectGraftingclipReturnById(graftingclipReturnId));
    }

    /**
     * 新增嫁接夹退回
     */
    @ApiOperation("新增嫁接夹退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:add')")
    @Log(title = "嫁接夹退回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GraftingclipReturn graftingclipReturn)
    {
        return toAjax(graftingclipReturnService.insertGraftingclipReturn(graftingclipReturn));
    }

    /**
     * 修改嫁接夹退回
     */
    @ApiOperation("修改嫁接夹退回")
    @ResponseBody
    @PreAuthorize("@ss.hasAnyPermi('production:graftingclipre:edit,production:graftingclipre:permit')")
    @Log(title = "嫁接夹退回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GraftingclipReturn graftingclipReturn)
    {
        return toAjax(graftingclipReturnService.updateGraftingclipReturn(graftingclipReturn));
    }

    /**
     * 删除嫁接夹退回
     */
    @ApiOperation("删除嫁接夹退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:remove')")
    @Log(title = "嫁接夹退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{graftingclipReturnIds}")
    public AjaxResult remove(@PathVariable Long[] graftingclipReturnIds)
    {
        return toAjax(graftingclipReturnService.deleteGraftingclipReturnByIds(graftingclipReturnIds));
    }

    /**
     * 获取嫁接夹类型下拉框
     */
    @ApiOperation("获取嫁接夹类型下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:type')")
    @GetMapping("/type")
    public TableDataInfo getType(){

        List<GraftingclipReturn> list = graftingclipReturnService.getGraftingclipType();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (GraftingclipReturn graftingclipReturn:list) {
            Long id = graftingclipReturn.getGraftingclipTypeId();
            String name = graftingclipReturn.getGraftingclipType();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<GraftingclipReturn> list = graftingclipReturnService.getUserName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (GraftingclipReturn graftingclipReturn:list) {
            Long id = graftingclipReturn.getUserId();
            String name = graftingclipReturn.getUserName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取口径型号下拉框
     */
    @ApiOperation("获取口径型号下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:specification')")
    @GetMapping("/specification/{graftingclipTypeId}")
    public TableDataInfo getSpecification(@PathVariable("graftingclipTypeId") Long graftingclipTypeId){

        List<String> list = graftingclipReturnService.getGraftingclipSpecification(graftingclipTypeId);
        return getDataTable(list);
    }

    /**
     * 获取公司下拉框
     */
    @ApiOperation("获取公司下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftingclipre:origincompany')")
    @GetMapping("/origincompany/{graftingclipTypeId}")
    public TableDataInfo getOriginCompany(@PathVariable("graftingclipTypeId") Long graftingclipTypeId){

        List<String> list = graftingclipReturnService.getOriginCompany(graftingclipTypeId);
        return getDataTable(list);
    }
}
